package com.demo.easy.manySheet;

import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author:YuXuePeng
 * @Date:Created in 2023/8/14 16:12
 */
public class DemoManySheetMain {
    public static void main(String[] args) {
        Map<String,Object> dataMap = new HashMap<>();
        List<String> list =  new ArrayList<>();
        List<User> users =  new ArrayList<>();
        users.add(new User("小明",22,"黑"));
        users.add(new User("小美",39,"江西"));
        users.add(new User("小军",31,"辽宁"));
        List<IPhones> phones =  new ArrayList<>();
        phones.add(new IPhones("13353307003","123@qq.com","13353307003"));
        phones.add(new IPhones("19978907980","456@163.com","19978907980"));
        phones.add(new IPhones("17777377377","789@qq.com","17777377377"));
        dataMap.put("one",users);
        dataMap.put("two",phones);
        InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("template/templateManySheet.xls");
//        InputStream inputStream = new DemoManySheetMain().getInputStream();
        ByteArrayOutputStream outputStream = DemoManySheetsUtil.outPutStreamByModelDemo(dataMap, inputStream);
        // 转换为字节数组
        byte[] byteArray = outputStream.toByteArray();

// 指定下载目录和文件名
        String outputPath = "C:\\Users\\JT\\Downloads\\测试.xlsx";

        try (FileOutputStream fileOutputStream = new FileOutputStream(outputPath)) {
            fileOutputStream.write(byteArray);
            fileOutputStream.flush();
            System.out.println("文件下载成功！");
        } catch (IOException e) {
            System.out.println("文件下载失败：" + e.getMessage());
        }
    }
    public InputStream getInputStream(){
        InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("template/templateManySheet.xls");
        return inputStream;
    }
}
